<template>
  <view class="filter">
    <span @click="handleShowFilter" class="search-filter">
      {{ text }}<uni-icons type="bottom" size="20"></uni-icons>
    </span>
    <uni-drawer ref="showLeft" mode="left" :width="320" class="search-panel">
      <view class="close">
        <u-icon name="close" @click="handleCloseFilter" title="关闭过滤条件"></u-icon>
      </view>
      <div class="panel-content">
        <slot></slot>
      </div>
      <div class="panel-foot">
        <div class="form-col-6"><u-button @click="handleReset" plain size="medium">重置</u-button></div>
        <div class="form-col-6"><u-button @click="handleConfirm" plain type="primary" size="medium">确定</u-button></div>
      </div>
    </uni-drawer>
  </view>
</template>

<script>
  export default {
    props: {
      text: {
        type: String,
        default: '筛选'
      }
    },
    methods: {
      // 显示过滤器
      handleShowFilter () {
        this.$refs.showLeft.open()
      },
      // 关闭过滤器
      handleCloseFilter () {
        this.$refs.showLeft.close()
      },
      // 确定
      handleConfirm () {
        this.$emit('confirm', this)
      },
      // 重置
      handleReset () {
        this.$emit('reset', this)
      }
    }
  }
</script>

<style lang="scss">
.filter {
  display: flex;
  align-items: center;
  .search-filter {
    display: flex;
    align-items: center;
    padding-right: 8px;
  }
  /deep/ .form-title {
    padding: 4px 15px;
    font-size: 14px;
    font-weight: 700;
  }
}
.search-panel {
  .close {
    position: absolute;
    top: 8px;
    right: 8px;
  }
  .panel-content {
    padding: 12px 0;
  }
  .panel-foot {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    text-align: center
  }
  .form-col-6 {
    float: left;
    box-sizing: border-box;
    padding: 0 8px;
  }
}
</style>